<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>选择酒店默认资源项</title>
<%@include file="../../head.jsp"%>


</head>
<body>
	<table id="list_datapic" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="resourceItemId" formatter="renderPickRatio">选择默认图片</th>
				<th field="resourceMiniImg" formatter="formatCell">酒店资源项图片</th>
			</tr>
		</thead>
	</table>

	<div id="addHotelResourceInfoDialog"
		style="width: 400px; height: 280px; padding: 10px 20px"></div>

	<script type="text/javascript">
		
	
		function formatCell(value, row, index) {
			return "<img src='${image_domain}"+value+"' width='150' height='100'>";
		}
		
		function renderPickRatio(value,row,index){
			   return "<input name='pickradio' type='radio'/>";
		}
		var pickStatus = false;
		$('#list_datapic')
				.datagrid(
						{
							title : "${resource.resourceName}",
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 'auto',
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : true,
							url : '${cpath }/admin/hotel/resource/pick/list?resourceId=${resource.resourceId}',
							remoteSort : false,
							idField : 'resourceItemId',
							singleSelect : true,//是否单选 
							pagination : false,//分页控件 
							rownumbers : true,//行号 
							onLoadSuccess:function(data){
						    	$(":radio[name='pickradio']").each(function(index){
						    		$(this).attr('index',index);
									$(this).click(function(){
										if (pickStatus == true){
											$.messager.alert("提示", '请不要重复勾选', "info");
											return;
										}
										pickStatus = true;
										var pickEle = $(this);
										var index = pickEle.attr('index');
										var rows = $('#list_datapic').datagrid('getData').rows;
										//var check = curCheckbox.attr('checked');
										var row = rows[index];
										row['resourceId'] = '${resourceId}';
										//if(check=='checked'){
											//row['checkInfo'] = 'add';
										//}

										var saveAction = "${cpath}/admin/hotel/resource/pick/save";
										$.post(saveAction, row, function(result) {
											if (result.resultCode === '00000000') {
												$.messager.alert("提示", result.resultMsg, "info");
												//关闭当前窗口
												$('#addHotelResourceInfoDialog').dialog('close');
												$('#list_data').datagrid('reload'); // reload the user data
												
											} else {
												pickStatus = false;
												$.messager.alert("错误", result.resultMsg, "error");
											}
										}, 'json');
									});
								});
						    }
						});
	  
		</script>
		<script type="text/javascript">
		</script>
</body>
</html>